﻿using CuteSprite.Eme.Data.Settlement;
using CuteSprite.Eme.UI.Utils;
using HmFramework.Components;
using HmFramework.Data;
using HmFramework.UI.Utils.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CuteSprite.Eme.UI.Settlement
{
  public partial class FrmBillingPriceDetail : EmeEntityForm
  {
    #region -- 属性 --

    private Int32 _BillingPriceID;

    public Int32 BillingPriceID
    {
      get { return _BillingPriceID; }
      set { _BillingPriceID = value; }
    }

    private BillingPriceDetail _CurrentBillingPrice;

    public BillingPriceDetail CurrentBillingPrice
    {
      get 
      {
        if (_CurrentBillingPrice != null) { return _CurrentBillingPrice; }
        _CurrentBillingPrice = CurrentEntity as BillingPriceDetail;
        return _CurrentBillingPrice;
      }
      set { _CurrentBillingPrice = value; }
    }
    #endregion

    #region -- 构造 --

    #region - 新增 -

    /// <summary>默认构造函数</summary>
    /// <param name="settlementSolutionID"></param>
    /// <param name="billingSolutionID"></param>
    /// <param name="entity"></param>
    public FrmBillingPriceDetail(IEntity entity)
      : base(entity, false)
    {
      InitializeComponent();
      InitForm();
    }

    /// <summary>默认构造函数</summary>
    /// <param name="settlementSolutionID"></param>
    /// <param name="billingSolutionID"></param>
    /// <param name="entity"></param>
    public FrmBillingPriceDetail(IEntity entity, Int32 billingpriceid)
      : base(entity, false)
    {
      BillingPriceID = billingpriceid;

      InitializeComponent();
      InitForm();
    }

    #endregion

    #region - 编辑 -

    /// <summary>构造函数</summary>
    /// <param name="settlementSolutionID"></param>
    /// <param name="entity">实体对象</param>
    /// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
    public FrmBillingPriceDetail(IEntity entity, Boolean readOnly)
      : base(entity, readOnly)
    {
      InitializeComponent();
      InitForm();
    }

    /// <summary>构造函数</summary>
    /// <param name="settlementSolutionID"></param>
    /// <param name="entity">实体对象</param>
    /// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
    public FrmBillingPriceDetail(IEntity entity, Boolean readOnly, Int32 billingpriceid)
      : base(entity, readOnly)
    {
      BillingPriceID = billingpriceid;

      InitializeComponent();
      InitForm();
    }
    #endregion

    #endregion

    #region -- 窗体事件 --

    #region - method InitComponent -

    ///// <summary>控件初始化</summary>
    protected override void InitComponent()
    {
      base.InitComponent();

      if (frmWeight == null) { frmWeight = FindControl("frmWeight") as NumberInput; }
      if (frmPrice == null) { frmPrice = FindControl("frmPrice") as NumberInput; }

      this.OnValid += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmBsdSettlementSolution_OnValid);
    }

    #endregion

    #region - 实体验证 -

    private void FrmBsdSettlementSolution_OnValid(object sender, EntityFormEventArgs e)
    {
      if (frmPrice.Text == String.Empty)
      {
        MessageBoxEx.Show("价格不能为空,请输入价格！", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        e.Cancel = true;
        return;
      }
      //if (frmBillingPriceID.SelectTarget == null)
      //{
      //  MessageBoxEx.Show("请选择计费价格！", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
      //  e.Cancel = true;
      //  return;
      //}
      if (frmWeight.Text == String.Empty)
      {
        MessageBoxEx.Show("重量不能为空,请输入重量！", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        e.Cancel = true;
        return;
      }
    }

    #endregion

    #region - method FormOnPreLoad -

    protected override void FormOnPreLoad()
    {
      base.FormOnPreLoad();

      if (IsAddNew)
      {
          CurrentBillingPrice.BillingPriceID = BillingPriceID;
      }
   
    }

    #endregion

    #endregion

  }
}
